/**
 * Created by yangshengjiepro on 15/5/18.
 */
/**
 * Created by yangshengjiepro on 15/4/23.
 */
//全局事件名称
var EVENT_UI_MAINTOP="maintop";

var EVENT_UI_MAIN_LISTVIEW="listview";

var UpdateUIManager=cc.Class.extend({
    _pageManagers:null,
    init:function(){
        this._pageManagers={};
    },
    /**
     * 添加事件监听
     * @param pageStr 标识在哪个page上(自定义的，不同page的pageStr不同)
     * @param func
     */
    addPageUpdateListeners :function(pageStr,func,targetObj, multiple){
        multiple = multiple || 0;
        if(!this._pageManagers[pageStr]){
            this._pageManagers[pageStr]=new signals.Signal();
        }

        if(!multiple){
            this._pageManagers[pageStr].removeAll();
        }
        this._pageManagers[pageStr].add(func,targetObj);
    },
    removeListeners:function(pageStr){
        if(this._pageManagers&&this._pageManagers[pageStr])
            this._pageManagers[pageStr].removeAll();
    },
    /**
     * 根据pageStr分发pageStr指定的页面的事件
     * @param pageStr
     * @param params type json
     */
    dispatch:function(pageStr,params){
        if(this._pageManagers[pageStr]){
            this._pageManagers[pageStr].dispatch(params);
        }
    }
});
UpdateUIManager.s_SharedPageManager = null;
UpdateUIManager.getInstance = function () {
    if (!UpdateUIManager.s_SharedPageManager) {
        UpdateUIManager.s_SharedPageManager = new UpdateUIManager();
        UpdateUIManager.s_SharedPageManager.init();
    }
    return UpdateUIManager.s_SharedPageManager;
};


///例子
var TestLayer=cc.Layer.extend({
     init:function(){
         return true;
     },
     refreshUI:function(data){

         //刷新UI逻辑
     },
     onEnter:function(){
         this._super();
         UpdateUIManager.getInstance().addPageUpdateListeners(EVENT_PAGE_MAINTOP,this.refreshUI,this);//绑定事件方法
     },
     onExit:function(){
         this._super();
         UpdateUIManager.getInstance().removeListeners(EVENT_PAGE_MAINTOP);//删除事件方法
     }
});

var TestLayer2=cc.Layer.extend({
     init:function(){
         var data;
         UpdateUIManager.getInstance().dispatch(EVENT_PAGE_MAINTOP,data);//触发事件方法
         return true;
     }
});